package com.sysfrog.cucumber;

/*
* Copyright (C) 2010 Thomas Heggelund
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*
*/

import com.sysfrog.cucumber.lexer.CucumberLexer;
import com.intellij.lang.cacheBuilder.DefaultWordsScanner;
import com.intellij.lang.cacheBuilder.WordsScanner;
import com.intellij.lang.findUsages.FindUsagesProvider;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiNamedElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static com.sysfrog.cucumber.lexer.CucumberTokenTypes.COMMENTS;
import static com.sysfrog.cucumber.lexer.CucumberTokenTypes.LITERALS;
import static com.sysfrog.cucumber.psi.CucumberElementTypes.VARIABLE_DEFINITION_FILTER;

public class CucumberFindUsagesProvider implements FindUsagesProvider {
    private WordsScanner wordsScanner;

    @Nullable
    public WordsScanner getWordsScanner() {
        if (wordsScanner == null) {
            wordsScanner = new DefaultWordsScanner(new CucumberLexer(), VARIABLE_DEFINITION_FILTER, COMMENTS, LITERALS);
        }
        return wordsScanner;
    }

    public boolean canFindUsagesFor(@NotNull PsiElement psiElement) {
        return false; 
    }

    @Nullable
    public String getHelpId(@NotNull PsiElement psiElement) {
        return null;  
    }

    @NotNull
    public String getType(@NotNull PsiElement element) {
        return "jalla";
    }

    public String getDescriptiveName(@NotNull PsiElement element) {
        if (element instanceof PsiNamedElement) {
            return ((PsiNamedElement) element).getName();
        }
        return null;
    }

    public String getNodeText(@NotNull PsiElement element, boolean useFullName) {
        if (element instanceof PsiNamedElement) {
            return element.getText();
        }
        return null;
    }
}
